//
//  NSString+DifferentColorString.m
//  PWAPhone
//
//  Created by sheng long on 14-3-22.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "NSString+DifferentColorString.h"

@implementation NSString (DifferentColorString)

//返回Label显示不同颜色的NSMutableAttributedString changeString需要特殊显示颜色的字体
-(NSMutableAttributedString*)returnNSMutableAttributedString:(NSString*)changeString
{
//    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:1];
//    [dic setObject:[NSNumber numberWithFloat:0] forKey:NSLigatureAttributeName];
//    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:self attributes:dic];

    NSRange ren = [self rangeOfString:changeString];
    NSMutableAttributedString *str = [[[NSMutableAttributedString alloc] initWithString:self] autorelease];
    [str addAttribute:NSForegroundColorAttributeName value:GET_COLOR(@"fcb798") range:ren];
    
    return str;
}

//返回Label显示不同颜色的NSMutableAttributedString changeString需要特殊显示颜色的字体
-(NSMutableAttributedString*)returnNSMutableAttributedString:(NSString*)changeString color:(UIColor*)color
{
    //    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:1];
    //    [dic setObject:[NSNumber numberWithFloat:0] forKey:NSLigatureAttributeName];
    //    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:self attributes:dic];
    
    NSRange ren = [self rangeOfString:changeString];
    NSMutableAttributedString *str = [[[NSMutableAttributedString alloc] initWithString:self] autorelease];
    [str addAttribute:NSForegroundColorAttributeName value:color range:ren];
    
    return str;
}

//返回正常日期
-(NSString*)returnNormalDate
{
    if (self.length>=10) {
        NSString *time = [self substringToIndex:10];
        if ([time isEqualToString:@"0001-01-01"]) {
            return @"无";
//            return [z_DateTime encodeTime:[NSDate date] format:PWA_DATA_TYPE];
        }
        return time;
    }
    return self;
}

//返回无字样
-(NSString*)returnWUText
{
    NSString *title = [self stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if (title.length==0) {
        return @"无";
    }
    return title;
}

//返回空字符串
-(NSString*)returnNilText
{
    if (self.length==0 || !self) {
        return @"";
    }
    return self;
}

//时间为无返回空字符串
-(NSString*)timeReturnNilText
{
    if (self.length==0 || !self || [self isEqualToString:@"无"]) {
        return @"0001-01-01";
    }
    return self;
}

//返回计划时间
-(NSString*)returnJHDate:(NSString*)jh
{
    NSString *s = [self returnNormalDate];
    if ([s isEqualToString:@"无"]) {
        return jh;
    }
    return s;
}

@end
